#include "homewindow.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QMenuBar>
#include <QTreeWidgetItem>
#include <QPushButton>

HomeWindow::HomeWindow(QWidget *parent) : QMainWindow(parent) {
    setWindowTitle("主页");

    // 创建主布局
    QWidget *centralWidget = new QWidget(this);
    setCentralWidget(centralWidget);
    QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget);

    // 创建顶部导航
    QHBoxLayout *headerLayout = new QHBoxLayout();
    QLabel *titleLabel = new QLabel("欢迎来到主页");
    headerLayout->addWidget(titleLabel);
    mainLayout->addLayout(headerLayout);

    // 创建菜单栏
    QMenu *fileMenu = menuBar()->addMenu("文件");
    fileMenu->addAction("个人信息", this, &HomeWindow::showUserInfo);
    fileMenu->addAction("修改密码", this, &HomeWindow::changePassword);
    fileMenu->addAction("退出登录", this, &HomeWindow::logout);

    // 创建侧边菜单
    QTreeWidget *sidebarMenu = new QTreeWidget(this);
    sidebarMenu->setHeaderLabel("管理菜单");
    QTreeWidgetItem *infoManagement = new QTreeWidgetItem(sidebarMenu, QStringList() << "信息管理");
    infoManagement->addChild(new QTreeWidgetItem(infoManagement, QStringList() << "科室信息"));
    infoManagement->addChild(new QTreeWidgetItem(infoManagement, QStringList() << "医生信息"));
    infoManagement->addChild(new QTreeWidgetItem(infoManagement, QStringList() << "患者信息"));
    QTreeWidgetItem *userManagement = new QTreeWidgetItem(sidebarMenu, QStringList() << "用户管理");
    userManagement->addChild(new QTreeWidgetItem(userManagement, QStringList() << "管理员信息"));

    mainLayout->addWidget(sidebarMenu);

    // 创建内容显示区
    stackedWidget = new QStackedWidget(this);
    mainLayout->addWidget(stackedWidget);

    // 添加页面
    QWidget *homePage = new QWidget();
    QLabel *welcomeLabel = new QLabel("欢迎使用医疗信息管理系统!");
    QVBoxLayout *homeLayout = new QVBoxLayout(homePage);
    homeLayout->addWidget(welcomeLabel);
    stackedWidget->addWidget(homePage);

    // 连接侧边菜单的信号
    connect(sidebarMenu, &QTreeWidget::itemClicked, this, &HomeWindow::loadPage);
}

void HomeWindow::showUserInfo() {
    // 显示用户信息
}

void HomeWindow::changePassword() {
    // 修改密码逻辑
}

void HomeWindow::logout() {
    // 退出登录逻辑
    close();
}

void HomeWindow::loadPage(QTreeWidgetItem *item, int column) {
    if (item->text(0) == "科室信息") {
        QLabel *departmentLabel = new QLabel("科室信息管理界面");
        stackedWidget->setCurrentWidget(departmentLabel);
    } else if (item->text(0) == "医生信息") {
        QLabel *doctorLabel = new QLabel("医生信息管理界面");
        stackedWidget->setCurrentWidget(doctorLabel);
    } else if (item->text(0) == "患者信息") {
        QLabel *patientLabel = new QLabel("患者信息管理界面");
        stackedWidget->setCurrentWidget(patientLabel);
    }
}
